package com.zjun.service.impl;

import com.zjun.mapper.MainDataMapper;
import com.zjun.pojo.MainDataPO;
import com.zjun.pojo.Result;
import com.zjun.service.BackendDataService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.text.Normalizer;
import java.util.HashMap;
import java.util.List;

@Service
public class BackendDataServiceImpl implements BackendDataService {
    @Autowired
    private MainDataMapper mainDataMapper;

    @Override// 获取所有数据
    public List<MainDataPO> selectAllData() {
        List<MainDataPO> mainDataPOList = mainDataMapper.select();
        return mainDataPOList;
    }

    @Override
    public Result insertData(String costType, String costDetail, String costPrice) {
        MainDataPO mainDataPO = new MainDataPO();
        mainDataPO.setCostType(costType);
        mainDataPO.setCostDetail(costDetail);
        mainDataPO.setCostPrice(Double.parseDouble(costPrice));
        mainDataMapper.insertData(mainDataPO);
        return new Result(1,"success",null);
    }


    @Override //给定所有的支出类型和支出细分
    public Result getFormOptions() {
        //接收支出类型和支出细分
        List<String> typeList = mainDataMapper.getTypeOptions();
        List<String> detailList = mainDataMapper.getDetailOptions();
        HashMap<String,List<String>> formOptions =  new HashMap<>();
        formOptions.put("costType",typeList);
        formOptions.put("costDetail",detailList);
        return new Result(1,"success",formOptions);
    }


}
